class DataIterator {
  private data: number[];
  private index = 0;
  constructor(container) {
    this.data = container.data;
  }

  next(): number | null {
    if (this.hasNext()) {
      return this.data[this.index++];
    }
    return null;
  }

  hasNext() {
    return this.index < this.data.length;
  }
}

class OrderData {
  data: number[];
  constructor(data) {
    this.data = data;
  }
  "Symbol.iterator"() {
    return new DataIterator(this); // 获取迭代器
  }
}

const instance = new OrderData([1, 2, 3, 4]);
const it = instance["Symbol.iterator"](); // 获取迭代器
while (it.hasNext()) {
  console.log(it.next()); // 1, 2, 3, 4
}
